package com.ibeeking.found.upms.cp.rest.controller.v1;

import com.ibeeking.found.upms.cp.rest.service.ILoginService;
import com.ibeeking.found.upms.service.common.param.CpUserRegisterParam;
import com.ibeeking.found.upms.service.common.query.CpUserRegisterQuery;
import com.ibeeking.found.upms.service.common.query.CpOauth2Query;
import com.ibeeking.found.upms.service.common.vo.CpUserRegisterVO;
import com.ibeeking.found.upms.service.common.vo.UrlVO;
import com.ibeeking.nematos.constants.enums.OperateLogTypeEnum;
import com.ibeeking.nematos.log.annotation.Log;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @ClassName  MemberController控制器
 * @Description
 * @Author ibeeking
 * @Date 2021-01-05 16:32
 **/
@RestController
@RequestMapping("/cp/open/v1")
public class CpUserOpenController {

    @Resource
    private ILoginService loginServiceImpl;


    @Log(logType = OperateLogTypeEnum.QUERY, describe = "根据手机号查询是否注册")
    @PostMapping(value = "/checkMobile/{mobile}")
    public CpUserRegisterVO checkMobile(@PathVariable("mobile")  String mobile) {
        return loginServiceImpl.checkMobile(mobile);
    }

    @Log(logType = OperateLogTypeEnum.QUERY, describe = "获取企业微信授权页面url")
    @PostMapping(value = "/getPreAuthUrl")
    public UrlVO getPreAuthUrl(@RequestBody @Validated CpOauth2Query query) throws Exception {
        return loginServiceImpl.buildPreAuthUrl(query);
    }

    @Log(logType = OperateLogTypeEnum.QUERY, describe = "用户授权登录应用")
    @PostMapping(value = "/loginByAuthorize")
    public CpUserRegisterVO loginByAuthorize(@RequestBody @Validated CpUserRegisterQuery query) {
        return loginServiceImpl.loginByAuthorize(query);
    }

    @Log(logType = OperateLogTypeEnum.QUERY, describe = "用户手机号登录应用")
    @PostMapping(value = "/loginByMobile")
    public CpUserRegisterVO loginByByMobile(@RequestBody @Validated CpUserRegisterQuery query) {
        return loginServiceImpl.loginByMobile(query);
    }

    @Log(logType = OperateLogTypeEnum.QUERY, describe = "用户注册")
    @PostMapping(value = "/register")
    public CpUserRegisterVO register(@RequestBody @Validated CpUserRegisterParam param) {
        return loginServiceImpl.registerNewUser(param);
    }
}
